﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Yeex.Boss.Web.Helper
{
    public static class CommonHelper
    {
        /// <summary>
        /// 获取字典中的值，如果没有则为空
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetDictionaryValue(Dictionary<string, object> dictionary, string key)
        {
            if (dictionary == null)
            {
                return string.Empty;
            }

            if (dictionary.ContainsKey(key))
            {
                return dictionary[key];
            }

            return string.Empty;
        }

        /// <summary>
        /// 获取字典中的值，如果没有则为默认值
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static object GetDictionaryValue(Dictionary<string, object> dictionary, string key, object defaultValue)
        {
            if (dictionary == null)
            {
                return defaultValue;
            }

            if (dictionary.ContainsKey(key))
            {
                return dictionary[key];
            }

            return defaultValue;
        }
    }
}